package com.t2c.tibetantochinese.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.t2c.tibetantochinese.R;
import com.t2c.tibetantochinese.base.BaseActivity;
import com.t2c.tibetantochinese.common.HttpRequest;
import com.t2c.tibetantochinese.common.HttpRequestManager;
import com.t2c.tibetantochinese.utils.SPUtil;
import com.t2c.tibetantochinese.views.TitleBar;

/**
 * Created by zoulu on 16/12/10.
 * 反馈页面
 */

public class FeedBackActivity extends BaseActivity {

    private EditText content;
    private Button btn;
    @Override
    protected int getContentViewResId() {
        return R.layout.feedback_layout;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView(){
        TitleBar titleBar = (TitleBar)findViewById(R.id.titlebar);
        titleBar.setTitle("反馈");
        titleBar.setOnLeftListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        content = (EditText) findViewById(R.id.content);
        btn = (Button) findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!TextUtils.isEmpty(content.getText().toString())){
                    HttpRequest httpRequest = HttpRequestManager.getInstance().sendFeedBack(new Response.Listener<String>() {
                        @Override
                        public void onResponse(String response) {
                            Log.e("feedback=", "onResponse: "+response );
                            Toast.makeText(FeedBackActivity.this,"反馈成功",Toast.LENGTH_SHORT).show();
                            content.setText("");
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(FeedBackActivity.this,"Server Error",Toast.LENGTH_SHORT).show();
                        }
                    }, SPUtil.get(FeedBackActivity.this,"name","").toString(),content.getText().toString());
                    httpRequest.commit();
                }else{
                    Toast.makeText(FeedBackActivity.this,"请输入反馈内容",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
